function EventEmitter(){
  this.events = {};
}
EventEmitter.prototype.on = function(eventName, cb) {
  if(!this.events) this.events = {}; // 如果
  const cbs = this.events[eventName] || [];
  cbs.push(cb)
  this.events[eventName] = cbs;
}
EventEmitter.prototype.emit = function(eventName, ...arg) {
  const cbs = this.events[eventName];
  console.log(cbs, arg)
  if (cbs) {
   cbs.forEach(fn=>fn(arg));
  } else {
    console.log(`没有订阅${eventName}这个事件`)
  }
}
EventEmitter.prototype.off =function(eventName, cb) {
 if (!this.events) this.events = {};
 if (this.events[eventName]) {
   this.events[eventName] = this.events[eventName].filter(fn=>fn!=cb|| fn.cb != cb )
 }

}
EventEmitter.prototype.once = function(eventName, cb) {
  const one = (...arg)=>{
    cb(...arg);
    this.off(eventName, one);
  }
  one.cb = cb;
  this.on(eventName,one)
}
const $ = new EventEmitter();
$.on('shopping',function(){
  console.log('shopping')
});
$.on('shopping',function(){
  console.log('shopping2')
});
$.on('shopping',function(){
  console.log('shopping3')
});
$.once('shopping', function(){
  console.log('i am once')
})

$.emit('shopping', 1,2,3,4,5)
// 设置对象的原型对象到另一个对象可以有以下几种方法
// var obj = {};
// obj = Object.create(Array.prototype);
// Object.setPrototypeOf(obj.__proto__, Array.prototype);
// obj.__proto__ = Array.prototype;